<template>
  <div class="compress">
    <el-card class="box-card">
      <template #header>
        <div class="card-header">
          <span>图片压缩</span>
        </div>
      </template>
      <p>点击下方按钮选择图片，输入图片目标大小</p>
      <p>支持多选，具体用法请查看组件源码</p>
    </el-card>
    <compress-img @upload-success="success" :size="50 * 1024" />
    <div class="compress-imgs">
      <div v-if="showImg">
        <el-row :gutter="10">
          <el-col
            :xs="24"
            :md="12"
            :lg="12"
            :xl="8"
            v-for="(item, index) of comressFiles.files"
            :key="index"
          >
            <el-card class="box-card">
              <template #header>
                <div class="card-header">
                  <span
                    >压缩后大小：{{
                      (item.file.size / 1024).toFixed(2)
                    }}
                    k</span
                  >
                </div>
              </template>
              <div class="box">
                <img :src="item.filePath" alt="" />
              </div>
            </el-card>
          </el-col>
        </el-row>
      </div>
    </div>
  </div>
</template>

<script setup>
import { reactive, ref } from "vue";
import compressImg from "@/components/jxf/compressImg/index.vue";
let comressFiles = reactive({ files: {} });
let showImg = ref(false);
function success(_files) {
  comressFiles.files = _files;
  showImg.value = true;
}
</script>

<style lang="scss" scoped>
.compress {
  padding: 10px;
  .box-card {
    margin: 10px 0;
    color: #777;
    .card-header {
      font-size: 20px;
    }
  }
  .box {
    height: 250px;
  }
  .el-col {
    margin-top: 10px;
  }
}
</style>
